﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Library.Utilities;
using DLV.Utilities;

namespace DLV.Data.Entities
{
    public class ConcernController
    {
        public int InsertConcern(ConcernInfo info)
        {
            return SQL.InsertConcern(info.ConcernFullName, info.ConcernSortName, info.ConcernEnglishName, info.SortDescription, info.DetailDescription, info.Phone, info.Hotline, info.Fax, info.Email, info.Website, info.RepresentName, info.Regency, info.ContinentId, info.NationalId, info.CityId, info.DistrictId, info.WardId, info.Address, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.ConcernType, info.PartnerId);
        }
        public void UpdateConcern(ConcernInfo info)
        {
            SQL.UpdateConcern(info.ConcernId, info.ConcernFullName, info.ConcernSortName, info.ConcernEnglishName, info.SortDescription, info.DetailDescription, info.Phone, info.Hotline, info.Fax, info.Email, info.Website, info.RepresentName, info.Regency, info.ContinentId, info.NationalId, info.CityId, info.DistrictId, info.WardId, info.Address, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.ConcernType, info.PartnerId);
        }
        public void DeleteConcern(ConcernInfo info)
        {
            DeleteConcern(info.ConcernId);
        }
        public void DeleteConcern(int concernId)
        {
            SQL.DeleteConcern(concernId);
        }
        public ConcernInfo GetConcern(int concernId)
        {
            return CBO.FillObject<ConcernInfo>(SQL.GetConcern(concernId));
        }
        public List<ConcernInfo> ListConcern()
        {
            return CBO.FillCollection<ConcernInfo>(SQL.ListConcern());
        }
        public List<ConcernInfo> ListConcernByType(int type)
        {
            return ListConcern().Where(p => p.ConcernType == type).ToList();
        }
        public DataTable SelectConcern()
        {
            return CBO.ConvertToDataTable(ListConcern(), typeof(ConcernInfo));
        }
        public DataTable SelectConcernByCar()
        {
            return CBO.ConvertToDataTable(ListConcern().Where(p=>p.ConcernType==3).ToList(), typeof(ConcernInfo));
        }
        public Dictionary<object, object> ListConcernLookup()
        {
            var users = ListConcernByStatus((int)Globals.DocumentStatus.Use).OrderBy(p=>p.ConcernFullName);
            var dicusers = new Dictionary<object, object>();
            foreach (ConcernInfo info in users)
                dicusers.Add(info.ConcernId, info.ConcernFullName);

            return dicusers;
        }
        public List<ConcernInfo> ListConcernByStatus(int status)
        {
            return CBO.FillCollection<ConcernInfo>(SQL.ListConcern()).Where(p => p.Status == status).ToList();
        }
        

       
    }
}
